package com.clothing.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 * @ClassName: LeaveMessage 
 * @Description: TODO(Entity) 
 * @author Charles 
 * @date 2017年10月18日 上午9:20:06 
 * @version 1.0
 */
@Entity
@Table(name = "leave_message")
public class LeaveMessage extends BaseEntity
{
    /** 
     * @Fields serialVersionUID : TODO(用一句话描述这个变量表示什么) 
     */ 
    private static final long serialVersionUID = 5707810622196544729L;

    /** 
     * @Fields serialVersionUID : TODO(用一句话描述这个变量表示什么) 
     */ 

    private User smallUser;
    
    private User bigUser;
    
    private String lastMessage;
    
    private Integer smallUnreadQuantity;
    
    private Integer bigUnreadQuantity;
    
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "small_user", nullable = false)
    public User getSmallUser()
    {
        return smallUser;
    }

    public void setSmallUser(User smallUser)
    {
        this.smallUser = smallUser;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "big_user", nullable = false)
    public User getBigUser()
    {
        return bigUser;
    }

    public void setBigUser(User bigUser)
    {
        this.bigUser = bigUser;
    }

    @Column(name = "last_message", nullable = false)
    public String getLastMessage()
    {
        return lastMessage;
    }

    public void setLastMessage(String lastMessage)
    {
        this.lastMessage = lastMessage;
    }
    
    @Transient
    public boolean isContain(Long userId)
    {
        return smallUser.getId().equals(userId) || bigUser.getId().equals(userId);
    }

    @Column(name = "small_unread_quantity", nullable = false)
    public Integer getSmallUnreadQuantity()
    {
        return smallUnreadQuantity;
    }

    public void setSmallUnreadQuantity(Integer smallUnreadQuantity)
    {
        this.smallUnreadQuantity = smallUnreadQuantity;
    }

    @Column(name = "big_unread_quantity", nullable = false)
    public Integer getBigUnreadQuantity()
    {
        return bigUnreadQuantity;
    }

    public void setBigUnreadQuantity(Integer bigUnreadQuantity)
    {
        this.bigUnreadQuantity = bigUnreadQuantity;
    }
}
